package cn.wolfcode.p2p.website.controller;

import cn.wolfcode.p2p.base.domain.RealAuth;
import cn.wolfcode.p2p.base.domain.UserInfo;
import cn.wolfcode.p2p.base.excetion.DisplayableExcetion;
import cn.wolfcode.p2p.base.service.*;
import cn.wolfcode.p2p.base.util.AjaxResult;
import cn.wolfcode.p2p.website.util.UploadUtil;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

//实名认证
@Controller
public class VideoauthController {

    @Autowired
    private IVideoauthService videoauthService;
    @Autowired
    private ILofinInfoService lofinInfoService;
    @Autowired
    private IOrdertimeService ordertimeService;
    @Autowired
    private IUserInfoService userInfoService;

    @RequestMapping("/videoAuditOrder")
    public String realAuth(Model model) {
        //判断当前用户的状态然后相应的跳转特免
        UserInfo userInfo = userInfoService.getCurrent();//当前登录的基本信息
        //videoOrder预约审核页面      videoOrder_result  审核通过界面
        if (userInfo.isHasVideoAuth()) {//已经审核
            //进入申请界面
            model.addAttribute("auditing", false);//预约成功带练习
            return "/videoOrder_result";
        } else {
            //进入申请页面
            if (userInfo.getVideoAuthId() == null) {
                //预约客服 auditors
                model.addAttribute("auditors", lofinInfoService.selectIsSuditorList());
                //预约日期 orderDates,当天的之后的五天
                List<Date> orderDates = new ArrayList<>();
                Date now = new Date();
                orderDates.add(now);
                orderDates.add(DateUtils.addDays(now, 1));
                orderDates.add(DateUtils.addDays(now, 2));
                orderDates.add(DateUtils.addDays(now, 3));
                orderDates.add(DateUtils.addDays(now, 4));
                model.addAttribute("orderDates", orderDates);
                //预约时间 orderTimes
                model.addAttribute("orderTimes", ordertimeService.selectAll());
                return "videoOrder";
            } else {
                //舔砖到已申请完毕界面,审核完成
                model.addAttribute("auditing", true);//预约成功带练习
                model.addAttribute("videoAuth", videoauthService.get(userInfo.getVideoAuthId()));
                return "/videoOrder_result";
            }
        }
    }

    //覅及预约按钮
    @RequestMapping("/videoAuth_apply")
    @ResponseBody
    public AjaxResult name(Long timeid, String orderDate, Long auditorId) {
        AjaxResult result = null;
        try {
            videoauthService.apply(timeid, orderDate, auditorId);
            result = new AjaxResult();
        } catch (DisplayableExcetion e) {
            e.printStackTrace();
            result = new AjaxResult(false, e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            result = new AjaxResult(false, "系统出错,请联系管理员");
        }
        return result;
    }


}
